/*
package com.starx.bctalk.service.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.starx.bctalk.common.constant.Constants;
import com.starx.bctalk.common.constant.RedisKeyConstant;
import com.starx.bctalk.common.entity.User;
import com.starx.bctalk.common.model.im.UserOnlineStatus;
import com.starx.bctalk.common.util.AESUtils;
import com.starx.bctalk.dao.mapper.UserMapper;
import com.starx.bctalk.service.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public int insert(User record) {

        return userMapper.insert(record);
    }

    @Override
    public User selectByIdAndSharding(Long id,int sharding) {
        return userMapper.selectByIdAndSharding(id,sharding);
    }

    //user token 按照 id + mac + 时间 的方式生成
    @Override
    public String createSession(String mac,User user) {
        //添加redis缓存
        redisTemplate.opsForValue().set(RedisKeyConstant.USER_INFO + user.getId(),user, Constants.SESSION_EXPIRES_TIME, TimeUnit.SECONDS);
        //更新token 缓存 用设备mac作为token缓存的key
        //***************************
        try {
            UserOnlineStatus onlineStatus = new UserOnlineStatus();
            onlineStatus.setUserId(user.getId());
            onlineStatus.setMac(mac);
            onlineStatus.setLastLoginTime(System.currentTimeMillis());
            //根据 id mac lastLoginTime 生成用户token
            String token = AESUtils.encrypt(JSONObject.toJSONString(onlineStatus),AESUtils.DEFAULT_KEY);
            user.setToken(token);
            onlineStatus.setToken(token);
            HashOperations<String, String, String> hps = redisTemplate.opsForHash();
            hps.put(RedisKeyConstant.USER_ONLINE_LIST + user.getId(),mac,JSONObject.toJSONString(onlineStatus));
            //设置缓存过期时间
            //redisTemplate.expire(RedisModulePrefix.USER_ONLINE_STATUS_.toString() + user.getId(),Constants.SESSION_EXPIRES_TIME, TimeUnit.SECONDS);
            return token;
        } catch (Exception e) {
            logger.error("createSession 失败: ",e);
            throw new RuntimeException(e);
        }
    }
}
*/
